package view.employee;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dal.employee.Employee;
import dal.employee.EmployeeUtil;

/**
 * Servlet implementation class UpdateEmployee
 */
@WebServlet("/UpdateEmployee")
public class UpdateEmployee extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public UpdateEmployee() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		PrintWriter printWriter = response.getWriter();
		response.setContentType("text/HTML");
		try {

			java.util.Date d = new java.util.Date();
			DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			String date = df.format(d);
			String dt[] = date.split("-");

			Date Date_Added = new Date(Integer.parseInt(dt[0]),
					Integer.parseInt(dt[1]), Integer.parseInt(dt[2]));
			String EmployeeId = request.getParameter("EmployeeId");
			String Name = request.getParameter("Name");
			String Current_Address = request.getParameter("CurrentAddress");
			String Permnt_Address = request.getParameter("PermntAddress");
			String Mobile = request.getParameter("Mobile");
			String Email_id = request.getParameter("EmailId");
			String Alternate_Email_id = request.getParameter("AlternateEmailId");
			String Designation = request.getParameter("Designation");

			Employee employee = new Employee();
			EmployeeUtil employeeUtil = new EmployeeUtil();

			//String employeeId = employeeUtil.getId();
			System.out.println(EmployeeId+""+Name+""+Current_Address+""+Permnt_Address+""+Mobile+""+Email_id+""+Alternate_Email_id+""+Designation);
			employee.setEmployeeId(EmployeeId);
			employee.setAlternateEmailId(Alternate_Email_id);
			employee.setCurrentAddress(Current_Address);
			employee.setPermenentAddress(Permnt_Address);
			employee.setDateAdded(Date_Added);
			employee.setDesignation(Designation);
			employee.setEmailId(Email_id);
			employee.setMobile(Mobile);
			employee.setName(Name);

			Boolean isOk = employeeUtil.update(employee);
			
			if(isOk=true)
			{
				printWriter.print(""
						+ "<b>"
						+ " Project Information Updated Succesfully "
						+ "</b>");
				
			}
			else
			{
				printWriter.print(""
						+ "<b>"
						+ " Project Information Not Updated Succesfully "
						+ "</b>");
				
			}

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

	}

}
